home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 076-100 / disk_097 / splines / bspline.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  4KB  |  128 lines

  1. /* The routines in this file are copyright (c) 1987 by Helene (Lee) Taran.
  2.  * Permission is granted for use and free distribution as long as the
  3.  * original author's name is included with the code.
  4.  */
  5.  
  6. #include "spline.h"
  7.  
  8. extern int DrawAFrame;
  9. REAL_POINT *TickMark();
  10. REAL_POINT *Midpoint();
  11.  
  12. /* Draw_Natural_Bspline : draws the bspline with natural ends that
  13.  * is defined by the list of <control_points>. Assumes that there
  14.  * are at least three control points.
  15.  */
  16. Draw_Natural_Bspline(w, control_points)
  17. struct Window *w;
  18. DLISTPTR control_points;
  19. {
  20.   REAL_POINT t1, t2, t3, t4, first, last;
  21.   DLISTPTR a = FIRST(control_points);
  22.   DLISTPTR b = NEXT(a);
  23.   DLISTPTR c = NEXT(b);
  24.  
  25.   first = *POINT(a);
  26.   TickMark(&t1,1,3,POINT(a),POINT(b));
  27.   TickMark(&t2,2,3,POINT(a),POINT(b));
  28.   if (DrawAFrame) DrawConstructionLine(w,POINT(a),POINT(b));
  29.   while (1) {
  30.       if (b == LAST(control_points)) { 
  31.          DrawBezierArc(w,&first,&t1,&t2,POINT(b));
  32.          return;
  33.       }
  34.       TickMark(&t3,1,3,POINT(b),POINT(c));
  35.       TickMark(&t4,2,3,POINT(b),POINT(c));  
  36.       TickMark(&last,1,2,&t2,&t3);
  37.       if (DrawAFrame) {
  38.           DrawConstructionLine(w,POINT(b),POINT(c));
  39.           DrawConstructionLine(w,&t2,&t3);
  40.       }
  41.       DrawBezierArc(w,&last,&t2,&t1,&first);
  42.       first = last; t1 = t3;  t2 = t4;  a = b;  b = c;  c = NEXT(c);
  43.   } 
  44. }
  45.  
  46. /* Draw_TripleKnot_Bspline : draws the bspline with triple knots at the ends
  47.  * defined by the list of <control_points>. Assumes that there
  48.  * are at least four control points.
  49.  */
  50. Draw_TripleKnot_Bspline(w, control_points)
  51. struct Window *w;
  52. DLISTPTR control_points;
  53. {
  54.   REAL_POINT t1, t2, t3, t4, first, last;
  55.   DLISTPTR a = FIRST(control_points);
  56.   DLISTPTR b = NEXT(a);
  57.   DLISTPTR c = NEXT(b);
  58.   DLISTPTR d = NEXT(c);
  59.   
  60.   if (DrawAFrame) DrawConstructionLine(w,POINT(a),POINT(b));
  61.  
  62.   first = *POINT(a);
  63.   t1 = *POINT(b);
  64.   if (LENGTH(control_points) == 4)  t2 = *POINT(c);
  65.   else TickMark(&t2,1,2,POINT(b),POINT(c));
  66.  
  67.   while (1) {
  68.  
  69.     if (d == LAST(control_points)) {  /* draw the last arc */
  70.        if (DrawAFrame) {
  71.            DrawConstructionLine(w,POINT(b),POINT(c));
  72.            DrawConstructionLine(w,POINT(c),POINT(d));
  73.        }
  74.        DrawBezierArc(w,&first,&t1,&t2,POINT(d));
  75.        return;
  76.     }
  77.  
  78.     if (d == PREVIOUS(LAST(control_points))) {
  79.       TickMark(&t3,1,2,POINT(c),POINT(d));
  80.       t4 = *POINT(d);
  81.     } else {
  82.       TickMark(&t3,1,3,POINT(c),POINT(d));  
  83.       TickMark(&t4,2,3,POINT(c),POINT(d));  
  84.     }
  85.  
  86.     TickMark(&last,1,2,&t2,&t3);
  87.     if (DrawAFrame) {
  88.         DrawConstructionLine(w,POINT(b),POINT(c));
  89.         DrawConstructionLine(w,&t2,&t3);
  90.     }
  91.     DrawBezierArc(w,&last,&t2,&t1,&first);
  92.     first = last; t1 = t3;  t2 = t4;  a = b;  b = c;  c = d; d = NEXT(d);
  93.   } 
  94. }
  95.  
  96.  
  97.  
  98. /* Draw_Closed_Bspline : draws the closed bspline that
  99.  * is defined by the list of <control_points>. Assumes that there
  100.  * are at least three control points. 
  101.  */
  102. Draw_Closed_Bspline(w, control_points)
  103. struct Window *w;
  104. DLISTPTR control_points;
  105. {
  106.   REAL_POINT t1, t2, t3, t4, first, last;
  107.   DLISTPTR a = FIRST(control_points);
  108.   DLISTPTR b = NEXT(a);
  109.   DLISTPTR c = NEXT(b);
  110.  
  111.   TickMark(&t1,2,3,POINT(LAST(control_points)),POINT(a));
  112.   TickMark(&t2,1,3,POINT(a),POINT(b));
  113.   TickMark(&first,1,2,&t1,&t2);
  114.   if (DrawAFrame) DrawConstructionLine(w,POINT(a),POINT(b));
  115.   do {
  116.       if (b == LAST(control_points)) c = FIRST(control_points);
  117.       TickMark(&t3,2,3,POINT(a),POINT(b));
  118.       TickMark(&t4,1,3,POINT(b),POINT(c));  
  119.       TickMark(&last,1,2,&t3,&t4);
  120.       if (DrawAFrame) {
  121.           DrawConstructionLine(w,POINT(b),POINT(c));
  122.           DrawConstructionLine(w,&t3,&t4);
  123.       }
  124.       DrawBezierArc(w,&first,&t2,&t3,&last);
  125.       first = last; t1 = t3;  t2 = t4;  a = b;  b = c;  c = NEXT(c);
  126.   } while (a != FIRST(control_points));
  127. }
  128.